package com.zdx.yswl.ui.tool;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.zdx.yswl.R;
import com.zdx.yswl.ui.bean.Device;

import java.util.List;

/**
 * Created by Lupengwei on 2015/8/6.
 */
public class DevGridAdapter extends BaseAdapter
{
    private Context context;
    private LayoutInflater inflater;
    private List<Device> listDevice;

    public DevGridAdapter(Context context, List<Device> listDevice)
    {
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.listDevice = listDevice;
    }

    @Override
    public int getCount()
    {
        return listDevice.size();
    }

    @Override
    public Object getItem(int position)
    {
        return null;
    }

    @Override
    public long getItemId(int position)
    {
        return 0;
    }
    static class ViewHolder
    {
        private Button cameOnline;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        if (convertView == null)
        {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.dev_grid_item, null);
            holder.cameOnline = (Button)convertView
                    .findViewById(R.id.online_cam);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.cameOnline.setText(listDevice.get(position).getTag());
        return convertView;
    }
}
